package com.ytc.order.controller;

import com.ytc.commons.model.dto.CourseOrderDto;
import com.ytc.commons.model.dto.PageRequest;
import com.ytc.commons.model.vo.CourseOrderVo;
import com.ytc.commons.model.vo.OrdersVo;
import com.ytc.commons.model.vo.ResponseResult;
import org.springframework.web.bind.annotation.*;
import com.ytc.order.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 订单前端控制器
 * </p>
 *
 * @author jiuye145
 */
@Slf4j
@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private OrdersService  ordersService;

    /*
    * //创建订单
    * 请求接口： POST： /orders/create/{coursePubId}
    * 参数：课程发布Id ， CoursePubId
    * 响应数据：ResponseResult<String>
    * */
    @PostMapping("/create/{coursePubId}")
    public ResponseResult<String> create(@PathVariable("coursePubId")Long coursePubId){
        return ordersService.create(coursePubId);
    }

    @PostMapping ( "/my-list" )
    public ResponseResult<CourseOrderVo> ordersList (PageRequest request, @RequestBody CourseOrderDto dto){
        return ordersService.ordersList(request,dto);
    }

    /*
    * //根据orderNO查询 ，订单支付状态
    * /orders/{orderNo}
    * GET
    * 参数：orderNo
    * 返回 ResponseResult<OrderVo>
    * */
    @GetMapping("/{orderNo}")
    public ResponseResult<OrdersVo> queryOrders(@PathVariable("orderNo") String orderNo){
        return ordersService.queryOrders(orderNo);
    }
}
